package com.info.zhiduoduo.repository.mapper.maker;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Condition;
import com.info.zhiduoduo.common.constants.Constants;
import com.info.zhiduoduo.repository.dto.maker.MakerAlipayIsvAgreementDto;
import com.info.zhiduoduo.repository.entity.maker.MakerAlipayAgreement;

import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2021-07-01
 */
public interface MakerAlipayAgreementMapper extends BaseMapper<MakerAlipayAgreement> {

	default MakerAlipayAgreement getByIsvIdAndUserid(int isvId, int userid) {
		return new MakerAlipayAgreement().selectOne(Condition.create().eq("isv_id", isvId).eq("userid", userid));
	}

	default boolean testPassed(int isvId, int userid) {
		return new MakerAlipayAgreement().setTestPassed(Constants.TRUE)
				.update(Condition.create().eq("isv_id", isvId).eq("userid", userid));
	}

	@Select(" select maa.isv_id,map.name as isvName,maa.status as agreementStatus,maa.test_passed, " +
			" ifnull(maab.available_amount, 0) as alipayAvailableAmount " +
			" from zdd_maker_alipay_agreement maa " +
			" join zdd_maker_alipay_principal map on map.id = maa.isv_id " +
			" join zdd_maker_alipay_account_book maab on maab.userid = maa.userid " +
			" where maa.userid = #{userid} ")
	List<MakerAlipayIsvAgreementDto> listByMakerid(int userid);

}
